package com.example.byd;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.util.Log;

import androidx.annotation.RequiresApi;


public class Onboot  extends BroadcastReceiver {


    @RequiresApi(api = Build.VERSION_CODES.O)
    @Override
    public void onReceive(Context context, Intent intent) {


        Log.i("bydsong","启动成功1");

        Intent newIntent = new Intent(context, GetLogCatService.class);  // 要启动的Activity
        //1.如果自启动APP，参数为需要自动启动的应用包名
      //  Intent intent = getPackageManager().getLaunchIntentForPackage(packageName);
            //        这句话必须加上才能开机自动运行app的界面
        newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        //2.如果自启动Activity
//        context.startActivity(newIntent);


        //3.如果自启动服务

            context.startForegroundService(newIntent);



//        try {
//            Thread.sleep(10);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//
//        Intent setIntent = new Intent(Intent.ACTION_MAIN);
//
//        setIntent.addCategory(Intent.CATEGORY_HOME);
//
//        setIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//
//        context.startActivity(setIntent);

        Log.i("bydsong","启动成功");


    }
}
